$title Demo model

* ------------------------------------------------------------------------------
* Demonstration model characterizing MPSGE features.
* Laurent Cretegny, CoPS, Monash University, Australia, 2004.
* ------------------------------------------------------------------------------

$if not exist demo.gdx $call gdxxrw i=demo.xls o=demo.gdx index=declare

sets
  s                 sector
  o                 commodity
  f                 primary factor;

parameters
  sam(*,*)          benchmark social accounting matrix
  interm(o,s)       intermediate demand [[use:o*s]]
  factor(f,s)       factor demand [[fac:f*s]]
  demand(o)         demand for consumption [[dem:o]]
  endow(f)          endowment [[end:f]]
  govdem(o)         government demand [[gov:o]]
  supply(s,o)       supply of output [[sup:s*o]]
  etrn(s)           elasticity of transformation [[etrn:s]]
  esub(s)           elasticity of substitution [[esub:s]]
  dt                change in output tax rate;

$gdxin demo
$load s o f etrn esub sam
$gdxin

interm(o,s) = sam(o,s);
factor(f,s) = sam(f,s);
demand(o) = sam(o,"ra");
endow(f) = sam("ra",f);
govdem(o) = sam(o,"gov");
supply(s,o) = sam(s,o) + sam("tya",o)$sameas(s,"s_agr")
              + sam("tyi",o)$sameas(s,"s_ind");
dt = 0;

$if not exist demo.har $include gdxtohar

$ontext
$model:demo

$sectors:
  y(s)              ! production
  c                 ! aggregate consumption
  va(s)             ! value added
  g                 ! government expenditure

$commodities:
  p(o)              ! price of commodity
  pc                ! price of aggregate consumption
  pg                ! price of a government output unit
  pva(s)            ! price index for value added
  pf(f)             ! price of primary factor

$consumers:
  ra                ! representative agent income
  gov               ! government income

$auxiliary:
  upl               ! unemployment index

$prod:y(s)          t:etrn(s)
  o:p(o)            q:supply(s,o)       p:0.8     a:gov     t:(0.2*(1+dt))
  i:p(o)            q:interm(o,s)
  i:pva(s)          q:(sum(f, factor(f,s)))

$prod:va(s)         s:esub(s)
  o:pva(s)          q:(sum(f, factor(f,s)))
  i:pf(f)           q:factor(f,s)

$prod:c             s:1.0
  o:pc              q:(sum(o, demand(o)))
  i:p(o)            q:demand(o)

$prod:g
  o:pg              q:(sum(o, govdem(o)))
  i:p(o)            q:govdem(o)

$demand:ra
  d:pc
  e:pf(f)           q:endow(f)
  e:pf("lab")       q:-endow("lab")     r:upl

$demand:gov
  d:pg

$constraint:upl
  pf("lab") / pc =e= 1;

$report:
  v:r_supply(s,o)   o:p(o)              prod:y(s)
  v:r_cons(o)       i:p(o)              prod:c

$offtext
$sysinclude mpsgeset demo

* Initial levels on auxiliary variables

upl.lo = -inf;
upl.l = 0;

* Benchmark replication

demo.iterlim = 0;
$include demo.gen
solve demo using mcp;
abort$(abs(demo.objval) gt 1e-7) "*** demo does not calibrate ! ***";
demo.iterlim = 1000;

* Fixation of a numeraire to allow comparison

ra.fx = ra.l;

* Counterfactual : 10% increase in tax rate on industrial output

dt = 0.1;

$include demo.gen
solve demo using mcp;

* Results

parameters
  res_com           results by commodity in % change from basis
  res_agg           aggregate results in % change from basis; 

res_com("s_agr",o) = (r_supply.l("s_agr",o)/supply("s_agr",o) - 1) * 100;
res_com("s_ind",o) = (r_supply.l("s_ind",o)/supply("s_ind",o) - 1) * 100;
res_com("cons",o) = (r_cons.l(o)/demand(o) - 1) * 100;
res_com("price",o) = (p.l(o) - 1) * 100;

res_agg("c") = (c.l - 1 ) * 100;
res_agg("pc") = (pc.l - 1 ) * 100;
res_agg("unemploy") = upl.l;
res_agg("ra_inc") = (ra.l/(sum(o, demand(o))) - 1 ) * 100;

option decimals = 6;
display res_com, res_agg;
